package core.job.executor;

import java.io.IOException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import process.service.MenuParserService;
import domain.web.model.Store;
import domain.web.model.StoreView;
import domain.web.service.StoreService;

@Component
public class ScheduleJobExecutor {
	
	@Autowired
	private StoreService storeService;
	@Autowired
	private MenuParserService menuParserService;
	
	@Scheduled(cron="0 0 0 1/4 * ?")
	public void doSchedule() {
		List<Store> stores = storeService.getAll();
		
		for (Store store : stores) {
			StoreView storeView = storeService.getView(store.getId());
			try {
				menuParserService.parse(storeView.getId(), storeView.getWebsite(),
						storeView.getMenuQ(), storeView.getPaginatorQ());
			} catch (IOException e) {
				continue;
			}
		}
		
		
	}
}
